package com.ghck.shop.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ghck.shop.dao.provider.UserAddressProvider;
import com.ghck.shop.model.UserAddress;


/** 
 * @author 作者 : chenxuan
 * @version 创建时间：2015年12月31日 上午10:20:47 
 * 类说明 
 */
public interface UserAddressMapper {

	
	@Insert("insert into user_address(user_id,mobile,tel,name,province_id,city_id,district_id,address,postcode,is_default,"
			+ "province,city,district)"
			+ " values(#{userId},#{mobile},#{tel},#{name},#{provinceId},#{cityId},#{districtId},#{address},"
			+ " #{postcode},#{isDefault},#{province},#{city},#{district})")
	@Options(useGeneratedKeys=true)
	public Integer addUserAddress(UserAddress userAddress);
	
	@InsertProvider(type=UserAddressProvider.class,method="modifyUserAddress")
	public Integer modifyUserAddress(UserAddress userAddress);
	
	@Delete("delete from user_address where id = #{id}")
	public void deleteUserAddress(Integer id);
	
	@Select("select * from user_address where id = #{userAddressId}")
	public UserAddress getUserAddressById(Integer userAddressId);
	
	@Select("select count(*) from user_address where user_id = #{userId}")
	public Integer countMyAddress(Integer userId);
	
	@Select("select * from user_address where user_id = #{userId}")
	public List<UserAddress> getUserAddressForAll(Integer userId);
	
	@Update("update user_address set is_default = 0 where user_id = #{userId}")
	public void updateUserAddressDefaultToNone(Integer userId);
	
	@Update("update user_address set is_default = 1 where user_id = #{userId} and id = #{id}")
	public void updateUserAddressDefault(UserAddress userAddress);
	
	@Select("select * from user_address where is_default = 1 and user_id = #{userId}")
	public UserAddress getUserAddressDefault(Integer userId);
}